<%--
  Created by IntelliJ IDEA.
  User: 92329
  Date: 2018/4/18
  Time: 17:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="common.jspf" %>
<html>
<head>
    <title>下载资源管理</title>
    <script>
        var param = {key: '', pageNum: 1};
        $(function () {
            load(param,1);
        })
        function load(param,sign) {
            $.ajax({
                url: "${hkxyPath}/downloads/downloads-list-json",
                type: "post",
                data: param,
                dataType: "json",
                success: function (result) {
                    if(result.code==1) {
                        $("#loadcartoon").hide();
                        var list=result.data;
                        if (list.length < 10) {
                            $("#loadovertip").show();
                            $("#loadmoreBtn").hide();
                        };
                        var htmlStr = '';
                        $.each(list, function (i, val) {

                            htmlStr += "<tr id=tr"+val.id+">" +
                                "<td><strong><a target='_blank' href='${hkxyPath}/downloads/downloads-show/"+val.id+"'>"+val.title+"</a></strong></td>" +
                                "<td>" + val.datetime + "</td>" +
                                "<td><button class='btn btn-primary btn-sm' onclick='deleteDownloads(" + val.id + ")'>删除</button></td>" +
                                "</tr>";
                        });
                        if (sign == 1) {
                            $("#downloadsList").html(htmlStr);
                        } else {
                            $("#downloadsList").append(htmlStr);
                        }
                    }else{
                        tips(0);
                    }
                },
                error: function (data) {
                    $("#loadcartoon").hide();
                }
            });
        }
        function addDownloads(){
            var formData = new FormData($("#addDownloadform")[0]);
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "${hkxyPath}/downloads/downloads-add" ,
                data: formData ,
                contentType: false,     //这个一定要写
                processData: false,    //这个一定要写
                success: function (result) {
                    if(result.code==1){
                        param.pageNum=1;
                        load(param,1);
                        tips(1);
                    }
                    else {
                        tips(0);
                        console.log(result.message);
                    }
                },
                error:function (){
                    tips(0);
                    console.log(result.message);
                }
            });
        }
        function search() {
            var keyword = $("#keyword").val();
            if (keyword == '') {
                param.key = '';
                param.pageNum=1;
                load(param,1);
            } else {
                param.key = keyword;
                param.pageNum=1;
                load(param,1);
            }
        }
        function deleteDownloads(id) {
            var trid="#tr"+id;
            var c = confirm("删除后不可恢复！！！\n确认删除？？？");
            if (c) {
                $(trid).remove();
                $.post("${hkxyPath}/downloads/downloads-delete", {id: id}, function (result) {
                    if(result.code==1) {
                        tips(1);
                    }else{
                        tips(0);
                        console.log(result.message);
                    }
                })
            }
        }

    </script>
    <style type="text/css">
        a:link {
            color: #000000;
            text-decoration: none;
        }
        a:visited {
            color: #000000;
            text-decoration: none;
        }
        a:hover {
            color: #999999;
            text-decoration: underline;
        }
    </style>
</head>
<body>
<!-- tips -->
<%@include file="tips.jspf"%>
<!-- Header -->
<div>
    <h2 class="header-bottom-my1">下载资源管理</h2>
</div>
<!-- Filter -->
<div class="padding-5">
    <button class='btn btn-primary pull-left' data-toggle="modal" data-target="#addDownloadsModal">增加资源</button>
    <div class="input-group col-md-offset-8 col-md-4">
        <input id="keyword" type="text" class="form-control" placeholder="查找资源">
        <span class="input-group-btn">
                <button class="btn btn-default" type="button" style="height: 34px;" onclick="search()">
                    <i class="fa fa-search"></i>
                </button>
            </span>
    </div>
</div>
<!-- List -->
<div class="padding-5 well" style="background-color:white;">
    <table class="table" style="padding-top: 10px;padding-bottom: 10px">
        <thead>
        <tr>
            <th class="col-md-8">标题</th>
            <th class="col-md-3">时间</th>
            <th class="col-md-1">操作</th>
        </tr>
        </thead>
        <tbody class="myLabelLink" id="downloadsList">

        </tbody>
    </table>
</div>
<!-- Loadmore -->
<script>
    function loadmore() {
        $("#loadcartoon").show();
        /*param.pageNum+=1;
        load(param,0);*/
    }
</script>
<div>
    <div id="loadcartoon" hidden>
        <p class="text-center"><img src="${imgPath}/loading.gif">正在加载</p>
    </div>
    <div id="loadovertip" hidden>
        <p class="text-center">没有更多数据了</p>
    </div>
    <div id="loadmoreBtn" class="loadmore" onclick="loadmore()">
        点击加载更多
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="addDownloadsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="modalLabel">增加资源</h4>
            </div>
            <div class="modal-body">
                <form role="form" id="addDownloadform">
                    <div class="form-group inline-form">
                        <label for="title">标题：</label>
                        <input type="text" class="form-control" name="title" maxlength="20" placeholder="写一个简短的标题（20字以内）">
                    </div>
                    <div class="form-group inline-form">
                        <label for="intro">介绍：</label>
                        <textarea ype="text" class="form-control" name="intro" rows="5" maxlength="500"></textarea>
                        <p class="help-block pull-right">500字以内</p>
                    </div>
                    <div class="form-group">
                        <label for="files">上传文件：</label>
                        <input id="files" type="file" name="files" size="2" multiple>
                        <p class="help-block">提示：在文件选择窗口内按住Ctrl可进行多选</p>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" id="close">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="addDownloads()" id="subBtn">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
</html>
